package com.BahavioralPartterns.observer.pull;

import java.util.ArrayList;
import java.util.List;
//http://blog.csdn.net/huanghailang/article/details/8351000
public class SimulationAwtButton {
	public static void main(String[] args) {
		Button b = new Button();
		b.addActionListener(new MyActionListener1());
		b.addActionListener(new MyActionListener2());
		b.pressed();
	}
}

class Button {
	private List<ActionListener> list = new ArrayList<ActionListener>();

	public void addActionListener(ActionListener l) {
		list.add(l);
	}

	public void pressed() {
		ActionEvent e = new ActionEvent(this);

		for (ActionListener l : list) {
			l.actionPerform(e);
		}
	}
}

interface ActionListener {
	void actionPerform(ActionEvent e);
}

class ActionEvent {
	private long time;
	private Object source;

	public ActionEvent(Object source) {
		this.time = System.currentTimeMillis();
		this.source = source;
	}

	public long getTime() {
		return time;
	}

	public Object getSource() {
		return source;
	}
}

class MyActionListener1 implements ActionListener {
	@Override
	public void actionPerform(ActionEvent e) {
		System.out.println("SimulationButton ActionPerformed:" + e.getTime()
				+ e.getSource());
	}
}

class MyActionListener2 implements ActionListener {
	@Override
	public void actionPerform(ActionEvent e) {
		System.out.println("SimulationButton ActionPerformed:" + e.getTime()
				+ e.getSource());
	}
}